﻿using System;
using System.Net;
using System.IO;
namespace ProcessesSMS
{
    /// <summary>
    /// Summary description for MUAVN.
    /// </summary>
    public class HANELCOM
    {
        #region Declare
        private SMS_MO WMO;
        private SMS_MT WMT;
        //ArrayList arr = new ArrayList();
        public HANELCOM(SMS_MO MO)
        {
            WMO = MO;
        }

        public HANELCOM()
        {
        }
        #endregion
        #region Method
        public void run()
        {
            WMT = new SMS_MT(WMO);
            string tmpMsg = WMO.Message.Substring(WMO.CommandCode.Length).Trim().Replace("  ", " ").Replace("  ", " ");
            tmpMsg = tmpMsg.Replace("  ", " ").Trim().ToUpper();
            string[] msg = tmpMsg.Split(new char[] { ' ' });
        
         //   wsReceiveMO.ReceiveMO ws = new ProcessesSMS.wsReceiveMO.ReceiveMO();
         //   int intval = ws.NhanMO(WMO.MO_ID, WMO.UserID, WMO.ServiceID, GetTelcoName(WMO.UserID), WMO.CommandCode, WMO.Message, "hanelcomsms", "hanelcom@7x62");
            string strMessageReturn="";
            int iMTTotal =0;
            wsHanelcom.SmsWebService wsHn = new ProcessesSMS.wsHanelcom.SmsWebService();
            int intval = wsHn.SendSMS(WMO.MO_ID,GetTelcoName(WMO.UserID),WMO.ServiceID,WMO.UserID,WMO.CommandCode,WMO.Message,true ,ConfigSettings.ReadSetting("KeyconnectMT"), ref strMessageReturn, ref iMTTotal);
            
            //WMT.AddMessage(WMO.UserID, intval.ToString(), SMS_ContentType.SMS_TEXT);
            //WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
            //WMT.Insert();
            return;
        }
        private string GetTelcoName(string phonenumber)
        {
            string str2number = phonenumber.Substring(2, 2);
            string str3number = phonenumber.Substring(2, 3);
            string telconame = "";
            if (str2number == "96" || str2number == "97" || str2number == "98" || str3number == "163" || str3number == "164" || str3number == "165" || str3number == "166" || str3number == "167" || str3number == "168" || str3number == "169")
                telconame = "VIETTEL";
            else if (str2number == "91" || str2number == "94" || str3number == "123" || str3number == "125" || str3number == "127" || str3number == "129")
                telconame = "VINAPHONE";
            else if (str2number == "90" || str2number == "93" || str3number == "120" || str3number == "121" || str3number == "122" || str3number == "126" || str3number == "128")
                telconame = "MOBIFONE";
            else if(str2number == "95")
                telconame = "SFONE";
            else if(str2number == "92" || str3number == "188")
                telconame = "VIETNAMOBILE";
            else if(str2number == "99" || str3number == "199")
                telconame = "BEELINE";
            else
                telconame = "Unname";
            return telconame;             
        }
        #endregion
    }
}
